package _04sql.work2;

import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) throws Exception {
        getConnection((byte) 1);
        getConnection((byte) 2);
        getConnection((byte) 3);
    }

    public static void getConnection(byte type) throws Exception {
        System.out.println("type"+type+"---------");
        Connection connection = null;
        DriverManager.registerDriver(new Driver());
        String url = "jdbc:mysql://localhost:3306/db?useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "123456";
        connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select name from market_region where type=" + type);
        List<String> list = new ArrayList<>();
        while (resultSet.next()) {
            list.add(resultSet.getString("name"));
        }
        list.forEach(System.out::println);
        connection.close();
        statement.close();
        resultSet.close();
    }
}